import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import UserLeaves from '../components/user/UserLeave'

import Allowance from '../components/allowance/Allowance'
import StaffGeneral from '../components/user/StaffGeneral'
import StaffFilter from '../components/user/StaffFilter'
import StaffLeave from '../components/user/StaffLeave'
import StaffAllowance from '../components/allowance/StaffAllowance'
import ContractsGeneral from '../components/contract/ContractsGeneral'
import ContractView from '../components/contract/ContractView'

Vue.use(VueRouter)
const router = new VueRouter({
    routes: [{
            path: '/',
            redirect: '/login'
        },
        {
            path: '/login',
            component: Login
        },
        {
            path: '/home',
            component: Home,
            redirect: '/welcome',
            children: [
                { path: '/welcome', component: Welcome },
                { path: '/users', component: Users },
                { path: '/userLeave', component: UserLeaves },
                { path: '/allowance', component: Allowance },
                { path: '/contract', component: ContractsGeneral },
                { path: '/staffGeneral', component: StaffGeneral },
                { path: '/staffLeave', component: StaffLeave },
                { path: '/contractView/:contractId/:isEdit/:isHR', component: ContractView },
                { path: '/staffAllowance', component: StaffAllowance },
                { path: '/staffFilter/:status', component: StaffFilter },
            ]
        },

    ]
});
// //路由守卫
// router.beforeEach((to, from, next) => {
//         if (to.path == '/login') {
//             return next();
//         }
//         const token = window.sessionStorage.getItem('token');
//         if (!token) {
//             return next('/login');
//         }
//         next()
//     })
    // 日期过滤器
Vue.filter('dateFormat', function(originVal) {
        const dt = new Date(originVal)
        const y = dt.getFullYear()
        const m = (dt.getMonth() + 1 + '').padStart(2, '0')
        const d = (dt.getDate() + '').padStart(2, '0')
        const hh = (dt.getHours() + '').padStart(2, '0')
        const mm = (dt.getMinutes() + '').padStart(2, '0')
        const ss = (dt.getSeconds() + '').padStart(2, '0')
        return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
    })
    // Vue.component('tree-table', TreeTable)
export default router
